/* 
 * File:   workspace.cpp
 * Author: jolo
 * 
 * Created on: 6. Oktober 2011, 20:01
 * Lincense: New BSD License (The BSD 2-Clause License)
 */

#include "workspace.hpp"

#include <core/application.hpp>

#include <QtGui/QSplitter>
#include <QtGui/QLayout>

#include <model/repository.hpp>

#include <widgets/entity_html_viewer.hpp>

#include "repository_tree_view.hpp"
#include "repository_tree_model.hpp"

namespace gui
{

    workspace::workspace(QWidget* p)
    : widgets::workspace(p)
    {
        setLayout(new QVBoxLayout(this));
        spl_ = new QSplitter(Qt::Horizontal, this);
        layout()->addWidget(spl_);

        rtm_ = new repository_tree_model(this);
        rtv_ = new repository_tree_view(spl_);
        rtv_->setModel(rtm_);
        ev_ = new widgets::entity_html_viewer(spl_);
        spl_->addWidget(rtv_);
        spl_->addWidget(ev_);
        
        connect(QApplication::instance(), SIGNAL(repository_opened(model::repository_ptr)),
                this, SLOT(on_repository_opened(model::repository_ptr)));
        connect(QApplication::instance(), SIGNAL(repository_closed()),
                this, SLOT(on_repository_closed()));
        connect(QApplication::instance(), SIGNAL(repository_opened(model::repository_ptr)),
                rtm_, SLOT(on_repository_opened(model::repository_ptr)));
        connect(QApplication::instance(), SIGNAL(repository_closed()),
                rtm_, SLOT(on_repository_closed()));
        
        connect(rtv_, SIGNAL(selected(model::entity_ptr)),
                ev_, SLOT(on_show_request(model::entity_ptr)));
    }

    workspace::~workspace()
    {
    }

    void workspace::on_repository_opened(model::repository_ptr r) {
        (void) r;
        setEnabled(true);
    }
    
    void workspace::on_repository_closed() {
        setEnabled(false);
    }

}